﻿$(function(){//延迟加载  
	var dvmodelId=$('#oltdvmodelId').val();
	var jfId=$('#jfId').val();
	var oltId=$('#oltId').val();
	var oltip=$('#oltip').val();
	var oltname=$('#oltname').val();
//	alert(dvmodelId);

	$('#xhrow').load('dvfirmsec?dvmodelId='+dvmodelId,function(){
		$.getScript('/xasj/js/component/dvmodelsec.js');
		$('#dvmodel').combobox({
			onChange:function(newValue,oldValue){
				if(newValue=='')return;
				$.ajax({
					url:'getmodelset?dvmodelId='+newValue,
					success:function(data){
						$('#oltponnum').numberbox('setValue',data.portnum);
						$('#boardnum').numberbox('setValue',data.boardnum);
						$('#ylpon').numberbox('setValue',parseInt(data.ylport));
						$('#zhukong').textbox('setValue',data.zhukong);
					}
				});
			}
		});
	});
	
	if(dvmodelId!=null&&dvmodelId!=''){
		$.ajax({
			url:'getmodelset?dvmodelId='+dvmodelId,
			success:function(data){
				$('#oltponnum').numberbox('setValue',data.portnum);
				$('#boardnum').numberbox('setValue',data.boardnum);
				$('#ylpon').numberbox('setValue',parseInt(data.ylport));
				$('#zhukong').textbox('setValue',data.zhukong);
			}
		});
	}
	
	$('#nextstep').linkbutton({
		iconCls:'icon-redo',
		onClick:function(){
			var ponnum=$('#oltponnum').val();
			var boardnum=$('#boardnum').val();
			var ylpon=$('#ylpon').val();
			var zhukong=$('#zhukong').val();
			var oltpppv=$('#oltpppv').val();
//			var oltiptvv=$('#oltiptvv').val();
//			var oltylv=$('#oltylv').val();
//			var oltvpv=$('#oltvpv').val();
			var dvfirm=$('#dvfirm').combobox('getValue');
			if(ponnum==''||boardnum==''||ylpon==''||zhukong==''){
				return;
			}
			$('#shownewonulist').datagrid({
				iconCls: 'icon-edit',
				singleSelect: true,
				url:'shownewonulist',
				width:'100%',
//				min-height:'350px',
				onClickRow: onClickonuRow,
				rownumbers:true,
				method:'POST',
				queryParams:{
					oltponnum:ponnum,
					ylpon:ylpon,
					boardnum:boardnum,
					dvfirm:'',
					oltId:oltId,
					oltip:oltip,
					oltpppv:oltpppv,
//					oltiptvv:oltiptvv,
//					oltylv:oltylv,
//					oltvpv:oltvpv,
					zhukong:zhukong,
					oltname:oltname,
					dvfirm:dvfirm
				},
				toolbar: [{
					iconCls: 'icon-save',
					handler: function(){
						acceptonu();
						}
					},
					'-'
					,{
					iconCls: 'icon-remove',
					handler: function(){
						rejectonu();
						}
					}],
				columns:[[{
					field:'onustatus',width:'7%',title:'状态',editor:{
						type:'combobox',
						options:{
							valueField:'statusvalue',
							textField:'status',
							data:[{
								statusvalue:'未分配',
								status:'未分配'
							},{
								statusvalue:'预留',
								status:'预留'
							},{
								statusvalue:'故障',
								status:'故障'
							}]
						}
					}
				},{
					field:'onuaddress',width:'7%',title:'地址',editor:{
						editable:false	    							
					}
				},{
					field:'onuepbaloc',width:'7%',title:'EPBA板',editor:{
						editable:false
					}
				},{
					field:'onupon',width:'7%',title:'PON口',editor:{
						editable:false
					}
				},{
					field:'onuobd',width:'7%',title:'OBD位置',editor:{
						editable:false
					}
				},{
					field:'onupppv',width:'8%',title:'pppoe vlan',editor:{
						editable:false
					}
				},{
					field:'iptvvlan',width:'8%',title:'iptv vlan',editor:{
						editable:false
					}
				},{
					field:'voipvlan',width:'8%',title:'voip vlan',editor:{
						editable:false
					}
				},{
					field:'ylvlan',width:'8%',title:'预留 vlan',editor:{
						editable:false
					}
				},{
					field:'onucvlan',width:'8%',title:'cvlan',editor:{
						editable:false
					}
				},{
					field:'pondetail',width:'8%',title:'ONU PON',editor:{
						editable:false
					}
				},{
					field:'onuodf',width:'8%',title:'ONU ODF',editor:{
						editable:false
					}
				}]],
				onLoadSuccess:function(){
					$('#compl').show();
				}
			});
		}
	});
	
	$('#compladdonu').linkbutton({
		iconCls: 'icon-ok',
		onClick:function(){
			var onulist=$('#shownewonulist').datagrid('getData');
			$.ajax({
				url:'completeaddonulist',
				type:'POST',
				data:{
					oltId:oltId,
					onulist:JSON.stringify(onulist),
				},
				success:function(data){
					alert(data.msg);
				}
			});
		}
	});
	
	var editIndex1 = undefined;	
	function endEditing1(){
		if (editIndex1 == undefined){return true}
		if ($('#shownewonulist').datagrid('validateRow', editIndex1)){
			//var ed = $('#dg').datagrid('getEditor', {index:editIndex,field:'productid'});
			//var productname = $(ed.target).combobox('getText');
			//$('#dg').datagrid('getRows')[editIndex]['productname'] = productname;
			//$('#dg').datagrid('endEdit', editIndex);
			editIndex1 = undefined;
			return true;
		} else {
			return false;
		}
	}
	function onClickonuRow(index){
		if (editIndex1!= index){
			if (endEditing1()){
				$('#shownewonulist').datagrid('selectRow', index)
						.datagrid('beginEdit', index);
				editIndex1 = index;
			} else {
				$('#shownewonulist').datagrid('selectRow', editIndex1);
			}
		}
	}
	function removeitonu(){
		if (editIndex1 == undefined){return}
		$('#shownewonulist').datagrid('cancelEdit', editIndex1)
				.datagrid('deleteRow', editIndex1);
		editIndex1 = undefined;
	}

	function acceptonu(){
		if (endEditing1()){
			$('#shownewonulist').datagrid('acceptChanges');
		}
	}

	function rejectonu(){
		$('#shownewonulist').datagrid('rejectChanges');
		editIndex1 = undefined;
	}
	
});